<template>
    <div class="page-wrap">
        <div class="menu" v-if="currentRoute!=='/login'">
            <div class="menu-container">
                <el-menu :default-active="routeHandled" mode="horizontal" router>
                    <el-menu-item v-for="item in menuList" :index="item.path">{{item.name}}</el-menu-item>
                </el-menu>
                <div class="user-info" v-if="username">
                    <span v-show="username">Hi：{{username}}</span>
                    <a href="" class="exit" @click.prevent.stop="doLogout">退出</a>
                </div>
            </div>
        </div>
        <router-view></router-view>
    </div>
</template>
<script>
import hub from 'common/hub';
import {cookie} from 'common/util';
import {mapGetters} from 'vuex';
export default {
    name: 'fcms',
    mounted() {
        this.init();
        hub.$on('login', username => {
            this.username = username;
        });
    },
    beforeDestroy() {
        hub.$off('login');
    },
    data() {
        return {
            username: cookie.get('username'),
            menuList: [{
                name: '內容管理',
                path: '/article-mng'
            }, {
                name: '欄目管理',
                path: '/column-mng'
            }, {
                name: '首頁配置',
                path: '/setting-index'
            }]
        };
    },
    computed: {
        routeHandled() {
            return this.currentRoute === '/' ? '/article-mng' : this.currentRoute;
        },
        ...mapGetters([
            'currentRoute'
        ])
    },
    watch: {
    },
    components: {},
    methods: {
        init() {},
        doLogout() {
            cookie.del('userid');
            cookie.del('username');
            this.username = '';
            this.$router.push('/login');
        }
    }
}
</script>
<style lang="less">
* {
    box-sizing: border-box;
}
html {
    height: 100%;
}
body {
    min-height: 100%;
}
@main-color: #01a896;
body {
    font-family: "Arial", "Hiragino Sans GB", "Microsoft YaHei", "微软雅黑", "SimSun", "宋体", HELVETICA;
    font-size: 14px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    margin: 0;
    overflow-x: hidden;
}

ul {
    padding: 0;
}

li {
    list-style-type: none;
}

a {
    text-decoration: none;
}

#app {
    width: 100%;
    margin: 0 auto;
}

.menu {
    background-color: @main-color;
    box-shadow: 0 2px 5px rgba(0,0,0,.2);
}

.menu-container {
    position: relative;
    margin: 0 auto;
    padding: 0 50px;
    border-radius: 0;
    .el-menu {
        background-color: transparent;
    }
    .el-menu-item {
        font-size: 16px;
        border-bottom: 0;
        color: #ddd;
        transition: all 0.3s;
        &.is-active {
            color: #fff;
            border-bottom: 5px solid #fff;
            &:hover {
                color: #fff;
                border-bottom: 5px solid #fff;
            }
        }
        &:hover {
            color: #fff;
            border-bottom: 0;
            background-color: rgba(0, 0, 0, 0.15);
        }
    }
    .user-info {
        position: absolute;
        right: 55px;
        top: 20px;
        color: #fff;
        a {
            color: #fff;
            &:hover {
                color: #ddd;
            }
        }
    }
    .exit {
        margin-left: 10px;
    }
}

.main-container {
    width: 100%;
    margin: 0px auto;
    padding: 20px 50px;
    .title {
        h2 {
            margin-top: 0;
            line-height: 40px;
        }
        position: relative;
        .pull-right {
            position: absolute;
            right: 0;
            top: 0;
            line-height: 40px;
            color: #20a0ff;
            &:hover {
                color: #4db3ff;
            }
        }
    }
}
.el-button--primary {
    color: #fff;
    background-color: @main-color;
    border-color: @main-color;
    transition: all 0.2s;
    &:hover {
        background-color: darken(@main-color, 5%);
        border-color: darken(@main-color, 5%);
    }
    &:active {
        background-color: darken(@main-color, 5%);
        border-color: darken(@main-color, 5%);
    }
    &:focus {
        background-color: darken(@main-color, 5%);
        border-color: darken(@main-color, 5%);
    }
}
.slide-left-enter-active, .slide-left-leave-active {
    transition: transform 0.3s;
    position: absolute;
}
.slide-left-enter {
    transform: translateX(-120%);
}
.slide-left-leave-active {
    transform: translateX(120%);
}
.slide-right-enter-active, .slide-right-leave-active {
    transition: transform 0.3s;
    position: absolute;
}
.slide-right-enter {
    transform: translateX(120%);
}
.slide-right-leave-active {
    transform: translateX(-120%);
}
.el-input__inner {
    max-width: 500px;
}
</style>
